package com.tqjc.business.interactivewithscan.entity;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.ToString;

/**
 * @program: C20005_Xianggang_new
 * @description: 坐标
 * @author: Patienyon
 * @create: 2023-11-06 10:08
 **/
@Data
@AllArgsConstructor
@ToString
public class Coord {
    private int x;
    private int y;
    private int z;
    private int testX;
    private int testY;
    private int testZ;

    @Override
    public String toString() {
        return "X:" + x + ",Y:" + y + ",Z:" + z + "\ttestX:" + testX + ",testY:" + testY + ",testZ:" + testZ;
    }

    public Coord() {

    }

    public Coord(Coord coord) {
        this.x = coord.getX();
        this.y = coord.getY();
        this.z = coord.getZ();
        this.testX = coord.getTestX();
        this.testY = coord.getTestY();
        this.testZ = coord.getTestZ();
    }

    public Coord(String coord) {
        String[] split = coord.split(",");
        if (split.length == 3) {
            this.x = Integer.parseInt(split[0].contains(".") ? split[0].substring(0, split[0].indexOf(".")) : split[0]);
            this.y = Integer.parseInt(split[1].contains(".") ? split[1].substring(0, split[1].indexOf(".")) : split[1]);
            this.z = Integer.parseInt(split[2].contains(".") ? split[2].substring(0, split[2].indexOf(".")) : split[2]);
        } else {

            this.x = 0;
            this.y = 0;
            this.z = 0;

        }
    }

    public Coord(String x, String y, String z) {
        this.x = Integer.parseInt(x);
        this.y = Integer.parseInt(y);
        this.z = Integer.parseInt(z);
    }

    public Coord(int x, int y, int z) {
        this.x = x;
        this.y = y;
        this.z = z;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj instanceof Coord) {
            boolean b1 = this.x - ((Coord) obj).getX() == 0;
            boolean b2 = this.y - ((Coord) obj).getY() ==0;
            boolean b3 = this.z - ((Coord) obj).getZ() == 0;
            if (b1 && b2 & b3) {
                return true;
            }
        }
        return false;
    }


    public String getIndexInfo(){
        StringBuilder sb = new StringBuilder();
        sb.append("X:").append(this.getX()).append(",Y:").append(this.getY()).append(",Z:").append(this.getZ());
        return sb.toString();
    }
}
